package freespiritsocial.io.user.ui.adapter

import androidx.core.view.isVisible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.UserInfo
import freespiritsocial.io.user.databinding.ItemPeopleBinding
import freespiritsocial.io.user.ext.setAdapterAnimation
import java.util.*

class PeopleAdapter
    (
    data: ArrayList<UserInfo> = arrayListOf(),
    private val isFollower: Boolean = false,
    private val hasBtn: Boolean = true,
    layoutResIdRes: Int = R.layout.item_people
):
    BaseQuickAdapter<UserInfo,BaseDataBindingHolder<ItemPeopleBinding>>(layoutResIdRes,data) {
    init {
        setAdapterAnimation(0)
        addChildClickViewIds(R.id.tv_follow,R.id.tv_remove,R.id.iv_avatar)
    }


    override fun convert(holder: BaseDataBindingHolder<ItemPeopleBinding>,item: UserInfo) {
        holder.dataBinding?.let {
            it.tvFollow.isVisible = hasBtn && !isFollower
            it.tvRemove.isVisible = hasBtn && isFollower
            it.user = item
        }
    }

    fun dealData(userInfo: UserInfo) {
        when (userInfo.eventStatus) {
            UserInfo.STATUS_ADD -> addData(userInfo)
            UserInfo.STATUS_DEL -> remove(userInfo)
        }
    }
}